// index.js
// 获取应用实例
let app = getApp()
let yuming = app.globalData.yuming
import * as echarts from '../components/ec-canvass/echarts';
let chart = null
var staffNum = ''
let reg = app.globalData.mobile
const util = require('../components/util');
const request = require('../../config/request');
const utils = require('../../utils/util.js')
//获取像素比
const getPixelRatio = () => {
  let pixelRatio = 0
  wx.getSystemInfo({
    success: function (res) {
      pixelRatio = res.pixelRatio
    },
    fail: function () {
      pixelRatio = 0
    }
  })
  return pixelRatio
}
// console.log(pixelRatio)
let dpr = getPixelRatio();

function initChart(canvas, width, height, dpr) {
  //初始化图表
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart);
  var option = {
    legend: {
      data: ['支付次数', '支出次数']
    },
    grid: {
      left: "0",
      containLabel: true
    },
    //当你选中数据时的提示框
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    //	x轴
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['09/06', '09/05', '09/04', '09/03', '09/02', '09/01'],
      // x轴的字体样式
      axisLabel: {
        show: true,
        textStyle: {
          color: '#989898',
          fontSize: '14',
        },
        interval: 0,
      },
      // 控制网格线是否显示
      splitLine: {
        show: false,
        //  改变轴线颜色
        lineStyle: {
          // 使用深浅的间隔色
          color: ['#aaaaaa']
        }
      },
      // x轴的颜色和宽度
      axisLine: {
        lineStyle: {
          color: '#989898',
          width: 1, //这里是坐标轴的宽度,可以去掉
        }
      }
      // show: false //是否显示坐标
    },
    yAxis: {
      x: 'center',
      type: 'value',
      // x轴的字体样式
      axisLabel: {
        show: true,
        textStyle: {
          color: '#989898',
          fontSize: '14',
        }
      },
      axisLine: {
        lineStyle: {
          color: '#989898',
          width: 1, //这里是坐标轴的宽度,可以去掉
        }
      },
      //网格线
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      // show: false
    },
    series: [{
        name: '支付次数',
        type: 'line',
        smooth: true,
        itemStyle: {
          color: "#ffa418"
        },
        data: [150, 3200, 3200, 316, 1785, 3770, 6650]
      },
      {
        name: '支出次数',
        type: 'line',
        smooth: true,
        itemStyle: {
          color: "#1bae18"
        },
        data: [200, 350, 6435, 460, 1300, 5700, 1300]
      }
    ]
    // //定义图标的标题和颜色
    //   title: {
    //     // text: '今日访问量',
    //     // left: 'center'
    //   },
    //   //定义你图标的线的类型种类
    //   tooltip: {
    //     trigger: 'axis',
    //     axisPointer: {            // 坐标轴指示器，坐标轴触发有效
    //       type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
    //     }
    //   },
    //   legend: {
    //     data: ['支付次数', '支出次数']
    //   },
    //   grid: {
    //     left:"0",
    //     containLabel: true
    //   },
    //   //当你选中数据时的提示框
    //   tooltip: {
    //     show: true,
    //     trigger: 'axis'
    //   },
    //   //	x轴
    //   xAxis: {
    //     type: 'category',
    //     boundaryGap: false,
    //     data: ['09/06', '09/05', '09/04', '09/03', '09/02', '09/01'],
    //     // x轴的字体样式
    //     axisLabel: {
    //       show: true,
    //       textStyle: {
    //         color: '#989898',
    //         fontSize: '14',
    //       },
    //       interval:0,
    //     },
    //     // 控制网格线是否显示
    //     splitLine: {
    //       show: false,
    //       //  改变轴线颜色
    //       lineStyle: {
    //         // 使用深浅的间隔色
    //         color: ['#aaaaaa']
    //       }
    //     },
    //     // x轴的颜色和宽度
    //     axisLine: {
    //       lineStyle: {
    //         color: '#989898',
    //         width: 1,   //这里是坐标轴的宽度,可以去掉
    //       }
    //     }
    //     // show: false //是否显示坐标
    //   },
    //   yAxis: {
    //     x: 'center',
    //     type: 'value',
    //     // x轴的字体样式
    //     axisLabel: {
    //       show: true,
    //       textStyle: {
    //         color: '#989898',
    //         fontSize: '14',
    //       }
    //     },
    //     axisLine: {
    //       lineStyle: {
    //         color: '#989898',
    //         width: 1,   //这里是坐标轴的宽度,可以去掉
    //       }
    //     },
    //     //网格线
    //     splitLine: {
    //       lineStyle: {
    //         type: 'dashed'
    //       }
    //     },
    //     // show: false
    //   },
    //   series: [
    //     {
    //       name: '支付次数',
    //       type: 'line',
    //       smooth: false,
    //       itemStyle:{
    //         color:"#ffa418"
    //       },
    //       data: [150, 3200, 3200, 316, 1785, 3770, 6650]
    //     },
    //     {
    //       name: '支出次数',
    //       type: 'line',
    //       smooth: false,
    //       itemStyle:{
    //         color:"#1bae18"
    //       },
    //       data: [200, 350, 6435, 460, 1300, 5700, 1300]
    //     }
    //   ]
  };
  /**绘制数据 */
  chart.setOption(option);
  return chart;
}

Page({
  ...request,
  data: {
    buttonClicked: false,
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    interval: 10000,
    heights: "",
    title: '',
    yuming: yuming,
    num: '',
    scanNum: 0,
    // background: [yuming + 'static/applet/images/index/baer1.png', yuming + 'static/applet/images/index/baer2.png'],
    // background: [{
    //   img: yuming + 'static/applet/images/index/indexbanner.jpg',
    //   url: '/my_dian/dui/dui'
    // }, {
    //   img: yuming + 'static/applet/images/index/yqfk.jpg',
    //   url: '/page_two/fangyi/fangyi'
    // }, {
    //   img: yuming + 'static/applet/images/index/shou4.jpg',
    //   url: '/page_other/shuju/shuju'
    // }],
    background: [],
    sonType: 0, //0默认  1子账号
    list2: [],
    // list2: [{
    //     colLogo: yuming + 'static/applet/images/index/jiben.png',
    //     colName: '经营信息',
    //     JumpUrl: '/page_one/xgdp/xgdp?title=经营信息',
    //     id: 1
    //   },
    //   {
    //     colLogo: 'https://s3.bmp.ovh/imgs/2021/10/4b829c42388d67aa.png',
    //     colName: '从业人员',
    //     JumpUrl: '/page_one/congye/congye?title=从业人员',
    //     id: 2
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/jianguan.png',
    //     colName: '监管提醒',
    //     JumpUrl: '/page_one/jianguan/jianguan?title=监管提醒',
    //     id: 3
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/zhibo.png',
    //     colName: '明厨直播',
    //     JumpUrl: '/page_one/jiankong/jiankong?title=明厨亮灶设备',
    //     id: 4
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/suyuan.png',
    //     colName: '溯源追踪',
    //     JumpUrl: '/page_one/suyuan/suyuan?title=溯源追踪',
    //     id: 5
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/suyuan.png',
    //     colName: '洗涤消毒',
    //     JumpUrl: '/page_two/publics/publics?title=洗涤消毒',
    //     id: 6
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/feiqi.png',
    //     colName: '废弃油脂',
    //     JumpUrl: '/page_two/publics/publics?title=废弃油脂',
    //     id: 7
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/shicai.png',
    //     colName: '食材质检',
    //     JumpUrl: '/page_two/publics/publics?title=食材质检',
    //     id: 8
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/miechong.png',
    //     colName: '灭虫管理',
    //     JumpUrl: '/page_two/publics/publics?title=灭虫管理',
    //     id: 9
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/tianjiaji.png',
    //     colName: '添加剂管理',
    //     JumpUrl: '/page_two/publics/publics?title=添加剂管理',
    //     id: 10
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/fenlei.png',
    //     colName: '公示牌',
    //     JumpUrl: '/page_two/study/study?title=公示牌',
    //     id: 11
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/fangyi.png',
    //     colName: '防疫上报',
    //     JumpUrl: '/page_two/fangyi/fangyi?title=防疫上报',
    //     id: 12
    //   },
    //   {
    //     colLogo: 'https://s3.bmp.ovh/imgs/2021/10/180e104950436b25.png',
    //     colName: '被投诉',
    //     JumpUrl: '/page_two/tousu/tousu?title=被投诉',
    //     id: 13
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/boss.png',
    //     colName: '区域广场',
    //     JumpUrl: '/page_two/bossquan/bossquan?title=区域广场',
    //     id: 14
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/dianzi.png',
    //     colName: '电子名片',
    //     JumpUrl: '/page_two/mingpian/mingpian?title=电子名片',
    //     id: 15
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/dtwb.png',
    //     colName: '电梯维保',
    //     JumpUrl: '/page_two/dtwb/dtwb?title=电梯维保',
    //     id: 16
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/xfsb.png',
    //     colName: '消防设备',
    //     JumpUrl: '/page_two/xfsb/xfsb?title=消防设备',
    //     id: 17
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/fwnr.png',
    //     colName: '服务内容',
    //     JumpUrl: '/page_two/fwnr/fwnr?title=服务内容及标准',
    //     id: 18
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/sfbz.png',
    //     colName: '收费标准',
    //     JumpUrl: '/page_two/shoufbz/shoufbz?title=收费标准',
    //     id: 19
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/sjsp.png',
    //     colName: '索记索票',
    //     JumpUrl: '/page_two/suojsp/suojsp?title=索记索票',
    //     id: 20
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/txy.png',
    //     colName: '特效药',
    //     JumpUrl: '/page_two/txdrug/txdrug?title=特效药',
    //     id: 21
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/ylqx.png',
    //     colName: '医疗器械',
    //     JumpUrl: '/page_two/yilqix/yilqix?title=医疗器械',
    //     id: 22
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/tsypcc.png',
    //     colName: '药品存储',
    //     JumpUrl: '/page_two/drugcc/drugcc?title=特殊药品存储',
    //     id: 23
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/xdsb.png',
    //     colName: '消毒设备',
    //     JumpUrl: '/page_two/xiaodsb/xiaodsb?title=消毒设备',
    //     id: 24
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/pxxx.png',
    //     colName: '培训学习',
    //     JumpUrl: '/page_two/peixxxi/peixxxi?title=培训学习',
    //     id: 25
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/ccsb.png',
    //     colName: '存储设备',
    //     JumpUrl: '/page_two/chucsb/chucsb?title=存储设备',
    //     id: 26
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/xsdj.png',
    //     colName: '销售登记',
    //     JumpUrl: '/page_two/saledj/saledj?title=销售登记',
    //     id: 27
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/rccj.png',
    //     colName: '日常抽检',
    //     JumpUrl: '/page_two/dailycj/dailycj?title=日常抽检',
    //     id: 28
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/sbdj.png',
    //     colName: '设备登记',
    //     JumpUrl: '/page_two/shebdj/shebdj?title=设备登记',
    //     id: 29
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/jljg.png',
    //     colName: '计量监管',
    //     JumpUrl: '/page_two/jiljg/jiljg?title=计量监管',
    //     id: 30
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/ylsb.png',
    //     colName: '游乐设备',
    //     JumpUrl: '/page_two/youlsb/youlsb?title=游乐设备',
    //     id: 31
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/ssdj.png',
    //     colName: '四实登记',
    //     JumpUrl: '/page_two/sisdj/sisdj?title=四实登记',
    //     id: 32
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/scsh.png',
    //     colName: '市场商户',
    //     JumpUrl: '/page_two/scsh/scsh?title=市场商户',
    //     id: 33
    //   },
    //   {
    //     colLogo: yuming + 'static/applet/images/index/yjx.png',
    //     colName: '意见箱',
    //     JumpUrl: '/page_two/yjx/yjx?title=意见箱',
    //     id: 34
    //   }
    // ],
    tongzhi: [],
    ping: [],
    zheng: [],
    ec: {
      lazyLoad: true
    },
    ecs: {
      lazyLoad: true
    },
    shopId: wx.getStorageSync('shopId'),
    zanfou: false,
    hangyeID: wx.getStorageSync('stryId'),
    mobile: '',
    get_code_btn: true,
    timer: '',
    count_down: '60', //验证秒数
    code: '', //验证码
    phone: '',
    wsdToken: '',
    power: '',
    createTime: '',
    isRefresh: true,
    wsddjs: '60', //获取温湿度秒数
    jgweidu: 0,
    grweidu: 0,
    likeNum: 0,
    yzshow: ''
  },
  // 温湿度mobile 
  mobile(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  // 温湿度验证码
  code(e) {
    this.setData({
      code: e.detail.value
    })
  },
  // 温湿度点击获取验证码
  huoqu() {
    var that = this
    if (that.data.mobile == '') {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
    } else if (that.data.mobile != '') {
      if (reg.test(that.data.mobile) == false) {
        wx.showToast({
          title: '请输入正确的手机号',
          icon: "none"
        })
      } else {
        that.yzm()
      }
    }
  },
  // 温湿度获取验证码接口
  yzm() {
    var that = this
    wx.request({
      url: 'https://sensor.jaalee.com/v1/login/code',
      method: 'GET',
      data: {
        account: that.data.mobile,
      },
      success: function (res) {
        wx.showToast({
          title: res.data.message,
          icon: 'none'
        })
        that.setData({
          get_code_btn: false
        })
        that.get_code_settime()
      },
      fail: function () {
        console.log("请求数据失败");
      }
    })
  },
  // 温湿度登录倒计时
  get_code_settime: function (that) {
    var that = this;
    var countDown = that.data.count_down; //获取倒计时初始值
    //如果定时器设置在外边，那么用户就看不到countDown的数值变化，所以要把定时器存进data里边
    that.setData({
      //这里把setInterval复制给变量名timer
      timer: setInterval(function () {
        countDown--;
        that.setData({
          get_code_btn: false, //此处用于隐藏验证码点击按钮，使倒计时显示
          count_down: countDown //倒计时计数 
        })
        //当计数为0时，清空定时器，使验证码按钮再次显示
        if (countDown == 0) {
          clearInterval(that.data.timer); //此处我清除timer之后，count_down没有变回我原先设定的120，get_code_btn也没有变回默认的true，咱没搞明白，所以我又重新赋值了
          that.setData({
            get_code_btn: true,
            count_down: '60'
          })
        }
      }, 1000)
    })
  },
  // 温湿度登录验证
  queren() {
    if (this.data.mobile == '') {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none'
      })
    } else if (this.data.mobile != '') {
      if (reg.test(this.data.mobile) == false) {
        wx.showToast({
          title: '请输入正确的手机号',
          icon: "none"
        })
      } else {
        if (this.data.code == '') {
          wx.showToast({
            title: '请输入验证码',
            icon: 'none'
          })
        } else {
          this.logins()
        }
      }
    } else if (this.data.code == '') {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
    } else if (this.data.code.length != 4) {
      wx.showToast({
        title: '请输入正确的验证码',
        icon: 'none'
      })
    } else {
      this.logins()
    }
  },
  // 温湿度登录接口
  logins() {
    var that = this
    wx.request({
      url: 'https://sensor.jaalee.com/v1/login',
      method: 'POST',
      data: {
        account: that.data.mobile,
        code: that.data.code,
      },
      success: function (res) {
        wx.showToast({
          title: res.data.message,
          icon: 'none'
        })
        if (res.data.code == 0) {
          that.setData({
            wsdToken: res.data.data.token
          })
          wx.setStorageSync('wsdToken', res.data.data.token)
        }
      },
      fail: function () {
        console.log("请求数据失败");
      }
    })
  },
  // 温湿度调取信息接口
  getWsd() {
    var that = this
    wx.request({
      url: 'https://sensor.jaalee.com/v1/open/data',
      method: 'GET',
      header: {
        Authorization: that.data.wsdToken
      },
      data: {
        bleMac: 'C86E5EB87F3D',
        page: 0,
        size: 1
      },
      success: function (res) {
        if (res.data.code == 0) {
          console.log(res)
          console.log(res.data)
          that.setData({
            wsdData: res.data.data.list[0],
            power: res.data.data.power,
            bleMac: res.data.data.mac,
            createTime: utils.formatTime(new Date(res.data.data.list[0].createTime))
          })
        }
      },
      fail: function () {
        console.log("请求数据失败");
      }
    })
  },
  // 温湿度刷新倒计时
  get_wsd_settime: function (that) {
    var that = this;
    that.setData({
      isRefresh: false, //此处用于隐藏验证码点击按钮，使倒计时显示
    })
    var countDown = that.data.wsddjs; //获取倒计时初始值
    //如果定时器设置在外边，那么用户就看不到countDown的数值变化，所以要把定时器存进data里边
    that.setData({
      //这里把setInterval复制给变量名timer
      timers: setInterval(function () {
        countDown--;
        that.setData({
          wsddjs: countDown //倒计时计数 
        })
        //当计数为0时，清空定时器，使验证码按钮再次显示
        if (countDown == 0) {
          clearInterval(that.data.timers); //此处我清除timer之后，count_down没有变回我原先设定的120，get_code_btn也没有变回默认的true，咱没搞明白，所以我又重新赋值了
          that.setData({
            isRefresh: true,
            wsddjs: '60'
          })
        }
      }, 1000)
    })
  },
  // 温湿度刷新
  update() {
    if (this.data.isRefresh == true) {
      this.get_wsd_settime();
      this.getWsd();
    } else {
      wx.showToast({
        title: `请${this.data.wsddjs}秒后再次尝试刷新`,
        icon: 'none'
      })
    }
  },
  // 经营信息
  xijing() {
    wx.navigateTo({
      url: '/page_one/xgdp/xgdp',
    })
  },
  backxqsss(e) {
    var url = e.currentTarget.dataset.url
    // console.log(url)
    if (url != '') {
      wx.navigateTo({
        url: url,
      })
    }
  },
  // 详情
  zcfgxq(e) {
    console.log(11)
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/page_other/zhengcfgxqs/zhengcfgxqs?id=' + id,
    })
  },
  getBanner() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Besall/public_banner', {
      alias: 'qs_home',
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        this.setData({
          background: res.data.data
        })
      }
      console.log(this.data.background);
    })
  },
  // 最新通知详情
  zxtzxq(e) {
    var id = e.currentTarget.dataset.id;
    var from = e.currentTarget.dataset.from;
    console.log(from)
    let curr = 0;
    if (from == '监管消息') {
      curr = 1;
    }
    wx.navigateTo({
      url: '/page_one/jianguanxq/jianguanxq?id=' + id + "&curr=" + curr + "&title=" + from + "详情",
    })
  },
  // 关注
  yiguan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    this.myRequest(yuming + 'shop/shopAddBossfollow', {
      shopId: wx.getStorageSync('shopId'),
      fid: id
    }, "POST").then(res => {
      // wx.showToast({
      //   title: res.data.msg,
      //   icon: 'none'
      // })
      that.wenz()
    })
  },
  // 两个分类
  // 溯源
  suyuan() {
    wx.navigateTo({
      // url: '/page_one/suyuan/suyuan?title=溯源追踪',
      url: '/page_two/fangyi/fangyi?title=防疫上报',
    })
  },
  yaoshi() {
    // wx.showToast({
    //   title: '暂未开通',
    //   icon: 'none'
    // })
    wx.navigateTo({
      url: '/page_other/zdysqy/zdysqy?title=驻店药师',
    })
  },
  // 分类
  fenlei0() {
    wx.navigateTo({
      // url: '/page_two/study/study?title=公示牌',
      url: '/page_one/jiankong/jiankong?title=明厨亮灶设备',
    })
  },
  // 分类
  fenlei1() {
    wx.navigateTo({
      // url: '/page_two/study/study?title=公示牌',
      url: '/page_one/jiankong/jiankong?title=店铺视频设备',
    })
  },
  // 数据
  shuju() {
    this.myRequest(yuming + 'Besall/findShopInfos', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      if (res.data.code == 200) {
        if (res.data.data != null) {
          let touxiang = '';
          if (res.data.data.shopLogo == null) {
            touxiang = '../../images/mrtx.png'
          } else {
            touxiang = res.data.data.shopLogo
          }
          this.setData({
            grxx: res.data.data,
            mobile: res.data.data.mobile,
            shopType: res.data.data.shopType,
            avatar: res.data.httpUrl + touxiang,
          })

          wx.setStorageSync('shopname', res.data.data.shopName)
          wx.setStorageSync('shopType', res.data.data.shopType)
          wx.setStorageSync('mobile', res.data.data.mobile)
          if (!res.data.data.stryId_fid) {
            wx.setStorageSync('stryId', res.data.data.stryId)
          } else {
            wx.setStorageSync('stryId', res.data.data.stryId_fid)
          }
          this.setData({
            hangyeID: wx.getStorageSync('stryId')
          })
        } else {
          wx.reLaunch({
            url: '/page_zhu/login/login',
          })
        }
      }
    })
  },
  // 栏目列表
  lmlist() {
    this.myRequest(yuming + 'shop/ShopSelectCartlist', {
      total: 1,
      shopId: wx.getStorageSync('shopId'),
      sonType: this.data.sonType,
      sonId: wx.getStorageSync('subId'), //子账号id
    }, "POST").then(res => {
      this.setData({
        list2: res.data.data
      })
    })
  },
  // 切换店铺
  qiehuan() {
    wx.navigateTo({
      url: '/page_zhu/xzdp/xzdp?mobile=' + this.data.mobile,
    })
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    var list = e.currentTarget.dataset.list
    var arr = []
    for (let i in list) {
      arr.push(list[i]); //属性
    }
    wx.previewImage({
      current: img,
      urls: arr
    })
  },
  // 医药模块配置须知页跳转
  pzxz() {
    wx.navigateTo({
      url: '/page_one/pzxz/pzxz?title=配置须知',
    })
  },
  // 监管提醒更多
  mores() {
    // wx.navigateTo({
    //   url: '/page_one/jianguan/jianguan?title=监管提醒',
    // })
    wx.switchTab({
      url: '/pages/xiaoxi/xiaoxi',
    })
  },
  // 区域社区更多
  qumore() {
    wx.navigateTo({
      url: '/page_two/bossquan/bossquan?title=区域社群',
    })
  },
  // 栏目详情
  xqs(e) {
    util.buttonClicked(this)
    var url = e.currentTarget.dataset.url
    var index = e.currentTarget.dataset.index
    if (url == '') {
      wx.showToast({
        title: `获得${this.data.likeNum}个赞呦~`,
        icon: 'none'
      })
    }
    if (wx.getStorageSync('stryId') == 6) {
      // if (index != 2) {
        wx.navigateTo({
          url: url,
        })
      // } else {
        // wx.showToast({
          // title: '暂未开通',
          // icon: 'none'
        // })
      // }
    } else {
      if (index != 3) {
        wx.navigateTo({
          url: url,
        })
      } else {
        wx.switchTab({
          url: url,
        })
      }
    }
  },
  // 扫码次数
  smcs() {
    wx.navigateTo({
      url: '/page_other/saomnum/saomnum',
    })
  },
  // 动态监管等级
  dtjgdj() {
    wx.navigateTo({
      url: '/page_other/dotaijgdj/dotaijgdj',
    })
  },
  // 收款码
  kuan() {
    // wx.showToast({
    //   title: '暂未开通',
    //   icon:'none'
    // })
    wx.navigateTo({
      url: '/page_other/shoukuan/shoukuan',
    })
  },
  list_xiang(e) {
    util.buttonClicked(this)
    var id = e.currentTarget.dataset.id + 1
    var cid = e.currentTarget.dataset.cid
    var url = e.currentTarget.dataset.url + "&cid=" + cid
    var index = e.currentTarget.dataset.index
    if (index == 2) {
      wx.switchTab({
        url: '/pages/xiaoxi/xiaoxi',
      })
    } else {
      if (url != null) {
        wx.navigateTo({
          url: url + "&id=" + id
        })
      } else {
        wx.showToast({
          title: '暂未开通',
          icon: 'none'
        })
      }
    }
  },
  // 点赞
  dianzan(e) {
    var id = e.currentTarget.dataset.id
    var iszan = e.currentTarget.dataset.iszan
    var index = e.currentTarget.dataset.index
    var that = this
    this.myRequest(yuming + 'shop/shopPubBossCircle', {
      shopId: wx.getStorageSync('shopId'),
      id: id
    }, "POST").then(res => {
      // wx.showToast({
      //   title: res.data.msg,
      //   icon: 'none'
      // })
      if (res.data.code == 200) {
        this.wenz();
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: 'none'
        })
      }
    })
  },
  // boss详情
  bossxq(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/page_two/bossxq/bossxq?id=' + id,
    })
  },
  // 文章、boss圈
  wenz() {
    this.myRequest(yuming + 'Besall/shopHome', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      // console.log(res)
      for (var i = 0; i < res.data.shopResult.length; i++) {
        res.data.shopResult[i].isshow = false
      }
      this.setData({
        zheng: res.data.ArticleResult,
        ping: res.data.shopResult,
        shopCount: res.data.shopCount,
        tongzhi: res.data.Reminder,
      })
      this.data.ping.forEach(item => {
        if (item.shopLogo == null) {
          item.shopLogo = '../../images/mrtx.png'
        }
      })
      this.setData({
        ping: this.data.ping
      })
      var data = res.data.homeData
      var that = this;
      if (wx.getStorageSync('stryId') == 6) {
        that.setData({
          list: [{
              name: '检查公示',
              num: data.patPublicity,
              url: '/my_other/hfjg/hfjg?title=检查公示'
            },
            {
              name: '抽检公示',
              num: data.bossCircle,
              // url: '/page_two/bossquan/bossquan?title=区域社群'
              url: '/page_other/choujian/choujian?title=抽检公示'
            },
            {
              name: '驻店药师',
              num: data.yaoshi_total,
              // url: '/page_two/bossquan/bossquan?title=区域社群'
              url: '/page_other/zdysqy/zdysqy?title=驻店药师'
            },
            {
              name: '被投诉',
              num: data.beComplaint,
              url: '/page_two/tousu/tousu?title=被投诉'
            },
            {
              name: '曝光台',
              num: data.bg_total,
              url: '/my_other/bgt/bgt?title=曝光台'
            }
          ],
          likeNum: data.likeNum
        })
      } else {
        that.setData({
          list: [{
              name: '从业人员',
              num: data.staffNum,
              url: '/page_one/congye/congye?title=从业人员'
            },
            {
              name: '溯源追踪',
              num: data.traceability,
              url: '/page_one/suyuan/suyuan?title=溯源追踪'
            },
            {
              name: '防疫上报',
              num: data.eppReport,
              url: '/page_two/fangyi/fangyi?title=防疫上报'
            },
            {
              name: '监管提醒',
              num: data.regReminder,
              url: '/pages/xiaoxi/xiaoxi'
            },
            {
              name: '检查公示',
              num: data.patPublicity,
              url: '/my_other/hfjg/hfjg?title=检查公示'
            },
            {
              name: '知识产权',
              num: data.intProperty,
              url: '/page_one/xgdp/xgdp?title=经营信息&currtab=2'
            },
            {
              name: '被投诉',
              num: data.beComplaint,
              url: '/page_two/tousu/tousu?title=被投诉'
            },
            {
              name: '被评论',
              num: data.beEvaluate,
              url: '/page_two/beievlute/beievlute?title=被评论'
            },
            {
              name: '被点赞',
              num: data.likeNum,
              url: ''
            },
            {
              name: '抽检公示',
              num: data.bossCircle,
              // url: '/page_two/bossquan/bossquan?title=区域社群'
              url: '/page_other/choujian/choujian?title=抽检公示'
            },
          ],
          likeNum: data.likeNum
        })
      }
    })
  },
  // 政策法规详情
  zhengxq() {
    wx.navigateTo({
      url: '/page_other/zhengcfgxq/zhengcfgxq',
    })
  },
  // 数字转文字
  changeNumber(num, point) { //num是传进来的具体数字，point是我们要保留的小数点个数
    var that = this
    let number = num.toString().split('.')[0] //第一步通过转换成字符串，利用.分割截取.前面的数字
    if (number.length < 6) { //对于万以下的数字我们不处理
      console.log(number)
      that.setData({
        num: number
      })
      return number //直接返回
    } else if (number.length >= 6 && number.length <= 8) { //第二步判断！小于6直接抬走，6-8即十百千万留下
      let demical = number.substring(number.length - 4, number.length - 4 + point) //这一步呢是拿到需要的小数
      let realnumber = parseFloat(parseInt(number / 10000) + '.' + demical) + '万' /*这一步呢是将原本的数除于10000再将之取int拿到小数点前的数，直接加万也行，加上拿到的小数也行！*/
      console.log(realnumber)
      that.setData({
        num: realnumber
      })
      return realnumber
    } else if (number.length > 8) { //这个是处理上亿的数了
      let demical = number.substring(number.length - 8, number.length - 8 + point)
      let realnumber = parseFloat(parseInt(number / 100000000) + '.' + demical) + '亿'
      console.log(realnumber)
      that.setData({
        num: realnumber
      })
      return realnumber
    }
  },
  yanzheng() {
    wx.showModal({
      title: '需要授权哦~',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          wx.redirectTo({
            url: '/page_zhu/shou/shou?sta=0&url=pages/index/index',
          })
        } else {
          wx.navigateBack({
            delta: 0,
          })
          console.log("取消")
        }
      }
    })
  },
  getsmjlList() {
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let that = this;
    this.myRequest(yuming + 'shop/shop_pay_scan_month', {
      shopId: wx.getStorageSync('shopId'),
      Year: 2022
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        let smlist = res.data.data.reverse();
        let cishu = [];
        let month = [];
        smlist.forEach(item => {
          cishu.push(item.pay_num);
          month.push(item.month)
        })
        // cishu = cishu.reverse();
        // month = month.reverse();
        this.setData({
          cishu,
          month
        })
        this.oneComponent.init((canvas, width, height) => {
          const chart = echarts.init(canvas, null, {
            width: width,
            height: height,
            devicePixelRatio: dpr // 加上这一行即可解决模糊问题
          });
          let option = {
            color: '#37A2FF',
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross',
                label: {
                  backgroundColor: '#6a7985'
                }
              }
            },
            legend: {
              data: ['扫码次数']
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            xAxis: [{
              type: 'category',
              boundaryGap: false,
              data: this.data.month
            }],
            yAxis: [{
              type: 'value'
            }],
            series: [{
              name: '扫码次数',
              type: 'line',
              stack: 'Total',
              smooth: true,
              lineStyle: {
                width: 0
              },
              showSymbol: false,
              label: {
                show: true,
                position: 'top'
              },
              areaStyle: {
                opacity: 0.8,
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgb(255, 191, 0)'
                  },
                  {
                    offset: 1,
                    color: 'rgb(255, 0, 135)'
                  }
                ])
              },
              emphasis: {
                focus: 'series'
              },
              data: this.data.cishu
            }]
          };
          this.setOption(chart, option);
          //this.chart = chart;
          return chart;
        });
      }
    })
  },
  gettsInfo() {
    wx.showLoading({
      title: '加载中',
    })
    this.myRequest(yuming + 'shop/shop_class_options', {
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading();
        let tsxx = [];
        res.data.data.forEach(item => {
          tsxx.push({
            value: item.option_total,
            name: item.name
          });
        })
        this.setData({
          tsxx
        })
        this.twoComponent.init((canvas, width, height) => {
          const chart = echarts.init(canvas, null, {
            width: width,
            height: height,
            devicePixelRatio: dpr // 加上这一行即可解决模糊问题
          });
          let option = {
            tooltip: {
              trigger: 'item',
              position: 'top',
            },
            legend: {
              orient: 'horizontal',


            },
            series: [{
              roseType: 'area',
              type: 'pie',
              radius: '55%',
              center: ["49%", "60%"],
              data: this.data.tsxx,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
              itemStyle: {

                normal: {
                  borderWidth: 2,
                  borderColor: '#FFF',
                  labelLine: {
                    length: -12,
                  },
                  color: function (colors) {
                    var colorList = [
                      '#3aa1fe',
                      '#37cbcb',
                      '#4fcb73',
                      '#fbd437',
                      '#f3637c',
                      '#a97be8',
                    ];
                    return colorList[colors.dataIndex];
                  }
                },
              }
            }]
          }
          this.setOption(chart, option);
          //this.chart = chart;
          return chart;
        });
      }
    })
  },
  setOption: function (chart, option) {
    var option = option;
    chart.setOption(option);
  },
  getCishu() {
    this.myRequest(yuming + 'shop/scan_shop_total', {
      shopId: wx.getStorageSync('shopId'),
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.setStorageSync('totalnum', res.data.data.scan_num)
        this.setData({
          scanNum: res.data.data.scan_num
        })
      }
    })
  },
  onLoad() {
    this.getBanner();
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      sonType: wx.getStorageSync('sonType')
    })
    wx.hideTabBar()
    // this.changeNumber(100000,3)
    if (wx.getStorageSync('token') == '') {
      this.setData({
        yzshow: true
      })
    }
    if (wx.getStorageSync('token') != '') {
      if (wx.getStorageSync('stryId') == 6) {
        if (wx.getStorageSync('wsdToken') != '') {
          this.setData({
            wsdToken: wx.getStorageSync('wsdToken')
          })
          this.get_wsd_settime();
          this.getWsd();
        }
      }
    }
    this.oneComponent = this.selectComponent('#mychart-dom-bar');
    this.twoComponent = this.selectComponent('#mychart-dom-bar1');
    // this.setData({
    //   scanNum: wx.getStorageSync('totalnum')
    // })
  },
  // 红点
  hongdian() {
    var that = this
    this.myRequest(yuming + 'besall/messageHongdian', {
      shopId: wx.getStorageSync('shopId'),
    }, "POST").then(res => {
      // console.log(res)
      that.setData({
        jgweidu: res.data.data.jg_count,
        grweidu: res.data.data.gr_count,
      })
    })
  },
  onShow() {
    this.setData({
      shopId: wx.getStorageSync('shopId')
    })
    this.shuju();
    this.wenz();
    this.hongdian();
    this.getsmjlList();
    this.gettsInfo();
    this.getCishu();
    this.lmlist()
    if (wx.getStorageSync('stryId') == 6) {
      this.getWsd();
    }
  }
})